package ${package}.controller;

import ${package}.common.Pager;
import ${package}.common.ResultFormat;
import ${package}.model.${table.name};
import ${package}.service.${table.name}Service;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/${table.tableName?replace('_', '-')}")
public class ${table.name}Controller {
    @Resource
    private ${table.name}Service ${table.name?uncap_first}Service;

    @GetMapping("/{id:\\d{1,20}}")
    public ${table.name} getById(@PathVariable ${table.idJavaType} id) {
        return ${table.name?uncap_first}Service.getById(id);
    }

    @GetMapping()
    public Pager list(${table.name} ${table.name?uncap_first}, Pager pager) {
        return ${table.name?uncap_first}Service.page(${table.name?uncap_first}, pager);
    }

    @ResultFormat
    @PostMapping()
    public int insert(@RequestBody ${table.name} ${table.name?uncap_first}) {
        return ${table.name?uncap_first}Service.insert(${table.name?uncap_first});
    }

    @ResultFormat
    @PutMapping()
    public int update(@RequestBody ${table.name} ${table.name?uncap_first}) {
        return ${table.name?uncap_first}Service.update(${table.name?uncap_first});
    }

    @ResultFormat
    @DeleteMapping()
    public Boolean delete(${table.idJavaType} id) {
        return ${table.name?uncap_first}Service.delete(id);
    }
}